package tongcheng.com.tongcheng.ui.yemian.shenfen.activity;

import android.os.Bundle;
import android.support.annotation.IdRes;
import android.support.v4.app.FragmentTransaction;
import android.util.Log;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;

import com.readystatesoftware.systembartint.SystemBarTintManager;

import butterknife.Bind;
import tongcheng.com.tongcheng.R;
import tongcheng.com.tongcheng.base.BaseActivity;
import tongcheng.com.tongcheng.base.main.FragmentOrder;
import tongcheng.com.tongcheng.ui.yemian.shenfen.fragment.InstallPersonCenterFragment;
import tongcheng.com.tongcheng.utils.Setting;

public class InstallPersonCenter extends BaseActivity {


    @Bind(R.id.main_fragment)
    LinearLayout mMainFragment;
    @Bind(R.id.main_rb1)
    RadioButton mMainRb1;
    @Bind(R.id.main_rb2)
    RadioButton mMainRb2;
    @Bind(R.id.main_rg)
    RadioGroup mMainRg;
    public static InstallPersonCenter ssInstance;
    @Override
    public Integer initResid() {
        return R.layout.activity_install_person_center;
    }

    @Override
    public void initCreate(Bundle savedInstanceState) {
        ssInstance = this;
        FragmentTransaction transactions = getTransaction();
        Log.e("temp", Setting.getTemp()+"");
        if (Setting.getTemp() == 1) {
            mMainRb2.setChecked(true);
            transactions.replace(R.id.main_fragment, new FragmentOrder());
        } else if (Setting.getTemp()==0) {
            mMainRb1.setChecked(true);
            transactions.replace(R.id.main_fragment, new InstallPersonCenterFragment());
        }
        transactions.commit();
        final SystemBarTintManager tintManager = getTintManager();
        mMainRg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, @IdRes int i) {
                final FragmentTransaction transaction = getTransaction();
                switch (i) {
                    case R.id.main_rb1:
                        Toast.makeText(InstallPersonCenter.this, "1", Toast.LENGTH_SHORT);
                        transaction.replace(R.id.main_fragment, new InstallPersonCenterFragment());
                        if (tintManager != null) {

                            tintManager.setStatusBarTintResource(R.color.title_barno);
                        }
                        break;
                    case R.id.main_rb2:
                        Toast.makeText(InstallPersonCenter.this, "1", Toast.LENGTH_SHORT);
                        transaction.replace(R.id.main_fragment, new FragmentOrder());
                        if (tintManager != null) {
                            tintManager.setStatusBarTintResource(R.color.title_bar);
                        }

                        break;
                }
                transaction.commit();
            }
        });
    }


    @Override
    protected void onDestroy() {
        super.onDestroy();
        Setting.setTemp(0);

    }
}
